package com.foreknow.sevlet;

import com.foreknow.model.User;
import com.foreknow.service.impl.UserServiceImpl;
import com.foreknow.service.userService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "RugusterServlet")
public class RugusterServlet extends HttpServlet {
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            resp.setContentType("text/html;charset=utf-8");
            req.setCharacterEncoding("utf-8");

        PrintWriter out = resp.getWriter();
        String username=req.getParameter("username");
        String account=req.getParameter("account");
        String password=req.getParameter("password");
        String phone = req.getParameter("phone");
        String email = req.getParameter("email");
       String avatar = req.getParameter("avatar");
        User[] users=new User[1];
       User user=new User( username,  account,  password,  phone,  email,  avatar);
        users[0]=user;
        userService se = new UserServiceImpl();
        if (se.Registered(users)){
            out.println("注册成功");
        }else{
            out.println("注册失败");
        }
    }



    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          doPost(request,response);
    }
}
